-
Notifications
You must be signed in to change notification settings - Fork 260
Do homework #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Do homework #51
Conversation
lwof
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Несколько небольших улучшений.
for_challenges.py
Outdated
| } | ||
| names = ['Оля', 'Петя', 'Вася', 'Маша'] | ||
| for name in names: | ||
| if is_male[name]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тут можно чуть сократить код. Как минимум нам хотелось бы что бы осталась только одна f-строка, что бы избежать двойного редактирования.
| if is_male[name]: | |
| gender = 'мужской' if is_male[name] else 'женский' | |
| print(f'{name} {gender}') |
| ['Оля', 'Петя', 'Гриша'], | ||
| ] | ||
| print(f'Всего {len(groups)} группы') | ||
| group_number = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тут вместо подсчета в переменной, лучше использовать enumerate, это более pythonic way. Плюс меньше ошибок, и другим разработчикам будет сразу понятно что мы просто последовательно все элементы нумеруем (а не что-то более хитрое)
for_dict_challenges.py
Outdated
| if student['first_name'] not in names: | ||
| names[student['first_name']] = 1 | ||
| else: | ||
| names[student['first_name']] += 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Как продвинутый вариант можно использовать get с аргументом по умолчанию 0:
| if student['first_name'] not in names: | |
| names[student['first_name']] = 1 | |
| else: | |
| names[student['first_name']] += 1 | |
| names[student['first_name']] = names.get(student['first_name'], 0) + 1 |
for_dict_challenges_bonus.py
Outdated
| import random | ||
| import uuid | ||
| import datetime | ||
| import pprint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
for_dict_challenges_bonus.py
Outdated
| if __name__ == "__main__": | ||
| print(generate_chat_history()) | ||
| messages = generate_chat_history() | ||
| # pprint.pprint(messages) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Старайся не забывать удалять закоментированый дебажный код.
string_challenges.py
Outdated
| # Вывести количество гласных букв в слове | ||
| word = 'Архангельск' | ||
| vowel_letters = 'аеёиоуыэюя' | ||
| counter = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
было бы отлично использовать чуть более конкретные имена вроде vowel_counter
No description provided.